// use stric mode.
'use strict';

module.exports = function (grunt) {
	require("time-grunt")(grunt);
	require("load-grunt-tasks")(grunt);
	// config setting
	var config = {
		backend: 'backend',
    frontend: 'frontend',
    dist: 'built'
	};
  var banner = [
    '/**',
    '* ' + (new Date()).toString(),
    '* Copyright© 2015-' + (new Date()).getFullYear() + ' ValueMaker All Rights Reserved.',
    '*/',
    ''
  ].join('\n');
  var webBuiltPath = grunt.option('path') || config.dist;
  // console.log(webBuiltPath);

	// define tasks.
	grunt.initConfig({
		config: config,
    compass: {
      dev: {
        options: {
          sassDir: ['web/src/sass'],
          cssDir: ['web/src/css/'],
          environment: 'development'
        }
      },
      prod: {
        options: {
          sassDir: ['web/sass/'],
          cssDir: ['web/css/'],
          environment: 'production'
        }
      },
      theme: {
        options: {
          sassDir: ['web/css/theme'],
          cssDir: ['web/css/theme']
        }
      }
    },
    uglify: {
      options: {
        banner: banner
      },
      dist: {
        files: [{
          expand:true,
          cwd: webBuiltPath + '/',
          src:'**/*.js',
          dest: webBuiltPath + '/'
        }]
      }
    },
    cssmin: {
      target: {
        files: [{
          expand: true,
          cwd: webBuiltPath + '/css/',
          src: '**/*.css',
          dest: webBuiltPath + '/css/'
        }]
      }
    },
    imagemin: {                         
      dist: {                         
        files: [{
          expand: true,                 
          cwd: webBuiltPath + '/img/',
          src: ['**/*.{png,jpg,gif}'],   
          dest: webBuiltPath + '/img/'
        }]
      }
    },
    watch: {
      options: {
        livereload: true,
      },
      compass: {
        files: [
          'web/src/sass/**/*.scss'
        ],
        tasks: ['compass:dev']
      },
      pageReload: {
        files: [
          'web/src/js/**/*.js',
          'views/**/*.php'
        ],
        tasks: []
      }
    }
	});

	// load task plugins.
  grunt.loadNpmTasks("grunt-contrib-compass");
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks("grunt-contrib-watch");
  grunt.loadNpmTasks("grunt-contrib-uglify");
  grunt.loadNpmTasks("grunt-contrib-imagemin");
  grunt.loadNpmTasks('grunt-contrib-cssmin');
	grunt.loadNpmTasks("grunt-sass");

	// define default task.
  grunt.registerTask("default", ['compass:dev']);
};